using System.Collections.Generic;
using System.Linq;
using FlickrNet;
using WroxGallery.Models.Interfaces;

namespace WroxGallery.Models.Implementations
{
    public class FlickrNETWrapper: IFlickrAPI
    {
        private Flickr _flickr;
        public FlickrNETWrapper()
        {
            _flickr= new Flickr();
        }

        public Photos PhotosSearch(string flickrUserName, int pageSize)
        {
            PhotoSearchOptions options = new PhotoSearchOptions(
                flickrUserName);
            options.PerPage = pageSize;
            return _flickr.PhotosSearch(options);
        }

        public Photos PhotosSearch(string flickrUserName, string tag, int pageSize)
        {
            PhotoSearchOptions options = new PhotoSearchOptions(flickrUserName);
            options.PerPage = pageSize;
            options.Tags = tag;
            options.TagMode = TagMode.AllTags;
            return _flickr.PhotosSearch(options);
        }

        public Photosets PhotosetsGetList(string flickrUserName)
        {
            return _flickr.PhotosetsGetList(flickrUserName);
        }

        public PhotoInfo PhotosGetInfo(string photoId)
        {
            return _flickr.PhotosGetInfo(photoId);
        }

        public IEnumerable<string> GetTags(string userId)
        {
            Tag[] tags = _flickr.TagsGetListUser(userId);
            return (from tag in tags
                    select tag.TagName);
        }

        public Photoset PhotosetsGetPhotos(string photoSetId, int pageSize)
        {
            return _flickr.PhotosetsGetPhotos(photoSetId, 1, pageSize);
        }

        public string APIKey
        {
            get { return _flickr.ApiKey; }
            set { _flickr.ApiKey = value; }
        }
    }
}